// Town 0, Battle for Gale

begintownscript;

variables;
short i,t,party_level,lvl;

body;

beginstate INIT_STATE;
	// get the average level of the party
	i = 0;
	while (i < party_size()) {
		if (char_ok(i))
			party_level = party_level + get_level(i);
		i = i + 1;
	}
	party_level = party_level / party_size;
	
	// upgrade all the monsters to the party's level
	i = 0;
	while (i < 233) {
		i = i + 1;
		if (i > 106 && i < 120)
			i = 120;
		if (i > 178 && i < 182)
			i = 182;
		if (i == 194)
			i = 195;
		if (char_on_spot(1,1) > 5)
			erase_char(char_on_spot(1,1));
		place_monster(1,1,i,1);
		lvl = get_level(char_on_spot(1,1));
		lvl = party_level + lvl - (party_level / 5 + 16);
		if (lvl < party_level && party_level < 10)
			lvl = party_level;
		set_creature_type_level(i,lvl);
	}
	erase_char(char_on_spot(1,1));
	print_str_color("(Hint: Move in any direction.)",2);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	move_to_new_town(1,22,25);
break;